$(function () {
	var gridSetting={
			url: '../runtime/process-instances',
			colModel: [			
				{ label: 'id', name: 'id', index: 'id', width: 50, key: true },
				{ label: 'processDefinitionId', name: 'processDefinitionId', index: 'processDefinitionId', width: 80 }, 			
				{ label: '状态', name: 'suspended', index: 'suspended', width: 80,formatter:function(cellvalue, options, rowObject){
					if (cellvalue) {
						return "挂起";
					}else{
						return "活动";
					}
				}  }, 			
				{ label: 'businessKey', name: 'businessKey', index: 'businessKey', width: 80 }, 			
				{ label: 'activityId', name: 'activityId', index: 'activityId', width: 80 }, 			
				{ label: 'tenantId', name: 'tenantId', index: 'tenantId', width: 80 }, 			
	        ],
	}
	gridSetting=$.extend(true,baseJqGridSetting,gridSetting);
    $("#jqGrid").jqGrid(gridSetting);
});

var vm = new Vue({
	el:'#rrapp',
	data:{
		showList: true,
		title: null,
		bpmProcessInstance: {}
	},
	methods: {
		query: function () {
			vm.reload();
		},
		showModel: function (event) {
			var id = getSelectedRow();
			if(id == null){
				return ;
			}
			var selectedRowData=getSelectedRowData()
		/*	var url='../modeler.html?modelId='+id;
			window.location.href=url;*/
			parent.layer.open({
				type:2,
				offset: '50px',
				skin: 'layui-layer-molv',
				title: "查看流程状态",
				area: ['1200px', '600px'],
				shade: 0,
				shadeClose: false,
				content: ['diagram-viewer/index.html?processDefinitionId='+selectedRowData.processDefinitionId+'&processInstanceId='+id, 'no'],
			});
		},
		activate: function (event) {
			var id = getSelectedRow();
			if(id == null){
				return ;
			}
			var param={};
			param.action="activate";
			$.ajax({
				type: "PUT",
			    url: "../runtime/process-instances/"+id,
			    data: JSON.stringify(param),
			    contentType: "application/json",
			    success: function(r){
			    	alert('操作成功', function(index){
						$("#jqGrid").trigger("reloadGrid");
					});
				}
			});
		},
		suspend: function (event) {
			var id = getSelectedRow();
			if(id == null){
				return ;
			}
			var param={};
			param.action="suspend";
			$.ajax({
				type: "PUT",
			    url: "../runtime/process-instances/"+id,
			    data: JSON.stringify(param),
			    contentType: "application/json",
			    success: function(r){
			    	alert('操作成功', function(index){
						$("#jqGrid").trigger("reloadGrid");
					});
				}
			});
		},
		del: function (event) {
			var id = getSelectedRow();
			if(id == null){
				return ;
			}
			confirm('确定要删除选中的记录？', function(){
				$.ajax({
					type: "DELETE",
				    url: "../runtime/process-instances/"+id,
				    contentType: "application/json",
				    success: function(r){
				    	alert('操作成功', function(index){
							$("#jqGrid").trigger("reloadGrid");
						});
					}
				});
			});
		},
		reload: function (event) {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{ 
                page:page
            }).trigger("reloadGrid");
		}
	}
});